package rexsee.device;

import rexsee.core.browser.Browser;
import rexsee.core.browser.clazz.JavascriptInterface;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;

public class RexseeInputMethod implements JavascriptInterface {

	private final Context mContext;
	private final Browser mBrowser;

	public static final String INTERFACE_NAME = "InputMethod";
	@Override
	public String getInterfaceName() {
		return mBrowser.application.resources.prefix + INTERFACE_NAME;
	}
	@Override
	public JavascriptInterface getInheritInterface(Browser childBrowser) {
		return this;
	}
	@Override
	public JavascriptInterface getNewInterface(Browser childBrowser) {
		return new RexseeInputMethod(childBrowser);
	}

	public RexseeInputMethod(Browser browser) {
		super();
		mBrowser = browser;
		mContext = browser.getContext();
	}

	public void disable() {
		InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.hideSoftInputFromWindow(mBrowser.getWindowToken(), 0);
	}
	public void enable() {
		InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.showSoftInput(mBrowser, 0);
	}

}
